package itheima.com.SocketTCPImg;

import java.io.*;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class ReSocketClienmt {

    public static void main(String[] args) throws Exception {


//        ServerSocket serverSocket = new ServerSocket(8888);
//        Socket accept = serverSocket.accept();
////        开始
//        System.out.println("客户端接收服务器请求·······"+accept.getClass());
//
//        String fliePath = "D:\\一条小团团\\xxx.jpg";
//        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fliePath));
//
//        byte[] bytes = StreamUtils.streamToByteArray(bis);
//
////        发送soket请求
//        new BufferedOutputStream(accept.)
//        System.out.println("bif---------"+bytes);

        Socket socket = new Socket(InetAddress.getLocalHost(),8888);
        System.out.println("客户端接收");

        String fliePath = "D:\\一条小团团\\xxx.jpg";
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fliePath));

        byte[] bytes = StreamUtils.streamToByteArray(bis);

//        发送soket请求
        BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
        bos.write(bytes);

        InputStream inputStream = socket.getInputStream();
        String s = StreamUtils.streamToString(inputStream);
        System.out.println(s);


        socket.shutdownOutput();

        bis.close();
        bos.close();
        socket.close();



    }

}
